package com.service.impl;

import com.service.FileUtilService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;

/**
 * ClassName: FileUtilServiceImpl
 * Package: com.service.impl
 *
 * @author: guanzepeng
 * @Date: 2021/4/30 16:09 星期五
 * @Description: 图片上传业务层
 */
@Service
@Slf4j
public class FileUtilServiceImpl implements FileUtilService {

	@Override
	public void uploadFile(byte[] file, String filePath, String fileName) throws Exception {
		log.info("进入uploadFile方法,要上传的图片名称为: {}",fileName);
		File targetFile = new File(filePath);
		if(!targetFile.exists()){
			boolean mkdirs = targetFile.mkdirs();
		}
		FileOutputStream out = new FileOutputStream(filePath+fileName);
		out.write(file);
		out.flush();
		out.close();
		log.info("uploadFile方法执行结束!");
	}
}
